<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card class="box-card">
      <el-row>
        <el-col :span="8">
          <el-input
            v-model="queryInfo.query"
            clearable
            placeholder="请输入内容"
            class="input-with-select"
            @change="getOrdersList"
          >
            <el-button slot="append" icon="el-icon-search" @click="getOrdersList"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格区域 -->
      <el-table :data="ordersList" stripe style="width: 100%">
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格(元)" width="120"></el-table-column>
        <el-table-column prop="order_pay" label="是否付款" width="120"></el-table-column>
        <el-table-column prop="pay_status" label="是否发货" width="120"></el-table-column>
        <el-table-column prop="update_time" label="下单时间" width="150">
          <template slot-scope="scope">
            {{ scope.row.update_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template>
            <el-button size="mini" type="primary" icon="el-icon-edit"></el-button>
            <el-button size="mini" type="danger" icon="el-icon-delete"></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="ordersHandleSizeChange"
        @current-change="ordersHandleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      ordersList: [],
      total: 0
    }
  },
  created() {
    this.getOrdersList()
  },
  methods: {
    async getOrdersList() {
      let { data: res } = await this.$axios.get('orders', { params: this.queryInfo })
      console.log(res)
      if (res.meta.status !== 200) {
        return this.$Message.error('获取数据失败')
      }
      this.ordersList = res.data.goods
      this.total = res.data.total
    },
    ordersHandleSizeChange(val) {
      this.queryInfo.pagesize = val
      this.getOrdersList()
    },
    ordersHandleCurrentChange(val) {
      this.queryInfo.pagenum = val
      this.getOrdersList()
    }
  }
}
</script>
<style lang="less" scoped></style>
